var gulp = require('gulp'),
    less = require('gulp-less'),                        //less编译
    autoprefixer = require('gulp-autoprefixer'),        //自动前缀
    cssmin = require('gulp-minify-css'),                //css压缩
    notify = require('gulp-notify'),                    //编译提示
    watch = require('gulp-watch');                      //变动监听

var src = 'src/';
var name = '';

//样式
gulp.task('style', function () {
    return  gulp.src(src + 'less/**/'+name+'.less')
        .pipe(less())
        .pipe(autoprefixer())
        //.pipe(cssmin())
        .pipe(gulp.dest(src + 'css/'))
        .pipe(notify({ message: 'Css编译完成' }));
});


//监听样式变动
gulp.task('style-watch', function() {
    gulp.watch(src + 'less/**/*.less',function(event){
        var str = event.path;
        str = str.match(/less\\(.+)\.less$/)[1];
        name = str.replace(/\\/,'/');
        gulp.start('style');
    });
});

gulp.task('style-all', function() {
    return  gulp.src(src + 'less/**/*.less')
        .pipe(less())
        .pipe(autoprefixer())
        //.pipe(cssmin())
        .pipe(gulp.dest(src + 'css/'))
        .pipe(notify({ message: 'Css编译完成' }));
});